﻿const shopId = 2;

var Temp = {};
Temp.lastRank = 0;
Temp.lastAmount = 'NaN';
$(function() {
	var shopId = qmsk.getQueryValue('shopId');
	var openId = qmsk.getQueryValue('openId');
	loadRank(shopId);
	loadCustomerRank(shopId, openId);
});

//

function loadCustomerRank(shopId, openId) {
	qmsk.get('../../../member/find/customerintegralRank/' + shopId + '/' + openId, function(response) {
		var amount = response.getValue("IntegralAmount");
		if (qmsk.isEmpty(amount)) {
			amount = 0;
		}
		$("#amount").text(amount);
		var rank = response.getValue('rank');
		if (amount == 0) {
			$("#rank").text('-');
		} else {
			$("#rank").text(rank);
		}
	});
}

function loadRank(shopId) {
	new qmsk.SiglePinterest({
		method : 'get',
		url : '../../../member/find/integralRank/' + shopId,
		initPage : 3,
		size : 10,
		success : printDataToPage,
		valves : 100,
		//emptyHandler : emptyHandler,
		loading : addRefresh2,
		loaded : delRefresh
	});
}

function printDataToPage(response) {

	qmsk.dataTable({
		tbodyId : 'rankList',
		heads : ["IntegralAmount", "CustomerName", "IntegralAmount"],
		response : response,
		empty : false,
		sup : ['clxx_simpleList_sup', '共 [index] 条'],
		handler : [[0, rankHandler]]
	});

	function rankHandler(amount, row) {
		if (amount == Temp.lastAmount) {
			return Temp.lastRank;
		} else {
			Temp.lastAmount = amount;
			Temp.lastRank = Temp.lastRank + 1;
			return Temp.lastRank;
		}

	}

}
